﻿@using System.Web.Mvc
@using System.Web.Mvc.Html;
@using System.Web.Routing
@using VocaDb.Model.DataContracts.Tags
@using VocaDb.Model.Domain
@using VocaDb.Model.Domain.Security
@using VocaDb.Web.Helpers
@inherits VocaDb.Web.Code.HelperPage

@helper PrintArchivedTagData(ComparedTagsContract comparedTags) {

	<div class="well well-transparent archived-entry-contents">
		<h4>Content</h4>

		<table class="table table-bordered">
			@ArchivedEntryHelpers.DataRow("Id", comparedTags.FirstData.Id)
			@ArchivedEntryHelpers.TranslatedNameRow(comparedTags, d => d.TranslatedName)
			@ArchivedEntryHelpers.DataRowList("Names", comparedTags, d => DataFormatUtils.GenerateHtmlFromHelper(d.Names, ArchivedEntryHelpers.NameInfo))
			@ArchivedEntryHelpers.DataRow("Description", comparedTags, d => d.Description)
			@ArchivedEntryHelpers.DataRow("Description English", comparedTags, d => d.DescriptionEng)
			@ArchivedEntryHelpers.ObjectRefList("Related tags", comparedTags, d => d.RelatedTags)
			@ArchivedEntryHelpers.DataRow("Valid for", comparedTags, d => d.Targets)
			@ArchivedEntryHelpers.DataRowList("External links", comparedTags, d => DataFormatUtils.GenerateHtmlFromHelper(d.WebLinks, ArchivedEntryHelpers.WebLinkInfo))
			@ArchivedEntryHelpers.DataRow("Category name", comparedTags, d => d.CategoryName)
			@ArchivedEntryHelpers.DataRow("Parent", comparedTags, d => ArchivedEntryHelpers.ObjectRefInfo(d.Parent))
		</table>

	</div>

}

@helper TagLink(TagBaseContract tag, bool tooltip = false) {
	@Html.ActionLink(tag.Name, "DetailsById", "Tag", new RouteValueDictionary { { "id", tag.Id }, { "slug", tag.UrlSlug }}, new Dictionary<string, object> { { "title", tag.AdditionalNames }, { "data-bind", tooltip ? "tagToolTip: " + tag.Id : null } })
}

@helper TagList(TagBaseContract[] tagNames, bool tooltip = false) {
	@Html.LinkListHtml(tagNames, t => TagLink(t, tooltip))
}

@helper TagUsagesManageTable(EntryType entryType, TagUsageWithVotesContract[] tagUsages, bool canRemove, string controllerName = null) {

	<div class="alert">
		You can use this to deassociate tags that are no longer valid for this entry. Be careful, this cannot be undone.
	</div>
	
	if (tagUsages.Any()) {
	<table>
		<thead>
			<tr>
				<th>Tag</th>
				<th>Count</th>
				@if (Login.CanManageUsers) { 
					<th>Votes</th>
				}
				<th>Date</th>
				<th></th>
			</tr>
		</thead>
		<tbody>
			@foreach (var usage in tagUsages) {
				<tr>
					<td>@TagLink(usage.Tag)</td>
					<td>@usage.Count</td>
					@if (Login.CanManageUsers) {
						<td>
							@foreach (var user in usage.Votes) {
								@UserHelpers.UserIconLink(user)<br />
							}
						</td>
					}
					<td>
						@usage.Date.ToShortDateString()
					</td>
					<td>
						@if (canRemove) {
							@Html.ActionLink("Remove tag usage", "RemoveTagUsage", controllerName ?? entryType.ToString(), new { id = usage.Id }, new { @class = "removeLink textLink", @onclick = "javascript: return confirm('Really delete?');" })
						}
					</td>
				</tr>
			}
		</tbody>
	</table>
	} else {
		@:No tags	 
	}

}